package mynote;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//登录按钮监听
public class LoginListener implements ActionListener {
    private LoginFrame login;
    private JTextField name;
    private JPasswordField pwd;

    public LoginListener(LoginFrame login, JTextField name, JPasswordField pwd) {
        this.login = login;
        this.name = name;
        this.pwd = pwd;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (LoginFrame.login(name.getText(), String.valueOf(pwd.getPassword()))) {
            login.rememberMe();
            login.dispose();
            new NoteFrame(name.getText()).setVisible(true);
        }
        else {
            JOptionPane.showConfirmDialog(null, "用户名或密码不正确！", "登录失败",
                    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE );
        }
    }
}
